<?php
/**
 * User Inbox List
 * 
 * It will display the list of connected Mail Box
 * 
 * @author Xavier VILAIN
 * @package Hive\User
 * @license #license-hive-social#
 */

use Fox\Behaviors;
use Fox\Html\Input;
use Fox\Html\Screen;
use Hive\Ressource\Source\Parser\Linkedin;
use Fox\Html\Button;
use Fox\Generator;
use Fox\Html\Header\Content;
$xview = Xview::instance();
$id = $xview->application()->getId();
// Customizing
$customizing = Hive\User\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'users','act'=>'inboxes','sac' => null));

$user = User::current();
// Page Title
$header = new Content('page-header',Msg(Hive::BUNDLE,Hive::MENU_MAILBOX_CONFIGURATION));

$html = Msg(Hive::BUNDLE,Hive::INBOX_CUSTOMIZING_HELP);
$html .= Xview::instance()->messages(true);

// 
if(count($user->personalMailers()) == 0) {
	
} else {

	$grid = new Fox\Grid('mailboxConfigurations');
	$grid->source(Generator::url('users','inboxes'));
	$grid->fieldcat(array('email','message','disable','ishare','ipwd','iedit','idele'));
	$grid->fieldcat()->switchToObjectMode();
	$grid->fieldcat()->setAllFieldsAttr('setClass','separator-left pad');
	$grid->fieldcat()->setAllFieldsAttr('headerCssClass','separator-left pad');
	$grid->fieldcat()->field('idele')->setClass('separator-left separator-right pad');
	$grid->fieldcat()->setGenerators(array(
		'message' => Generator::useFunction(function($data){
			$sync = $data->lastSynchronization();
			if(!empty($sync)) {
				$date = \Fox\Utilities\DateTimes::toFullString($sync->sync_date);
				if($sync->inError()) {
					return '<p class="text-error">'.Msg(Orx\Mailer\Messages::BUNDLE,Orx\Mailer\Messages::LAST_SYNCHRONIZATION_ON_ERROR,$date,$sync->message).'</p>';
				} else {	
					$message_count = ($sync->message_count > 0) ? $sync->message_count : 0;
					return Msg(Hive::BUNDLE,Hive::LAST_INBOX_CHECK_ON_NB_MESSAGES,$date,$message_count);
				}
			}
		}),
		'ipwd' => Generator::useValue(' '),
		'ishare' => Generator::useValue(' '),
		'iedit' => Generator::useValue('?'),
		'idele' => Generator::useValue('?'),
	));

	
	$grid->fieldcat()
			->field('iedit')->renderer()->behaviors(Behaviors::action(
				Generator::url('messages','mailbox','save',array('inlineid' => Generator::call('getInLineId'))),
				true
			)
	);
	$grid->fieldcat()
			->field('idele')->renderer()->behaviors(Behaviors::action(
				Generator::url('messages','mailbox','delete',array('inlineid' => Generator::call('getInLineId'))),
				true
			)
	);
	$grid->fieldcat()
			->field('ishare')->renderer()->behaviors(Behaviors::action(
				Generator::url('messages','mailbox','share',array('inlineid' => Generator::call('getInLineId'))),
				true
			)
	);
	$grid->fieldcat()
			->field('ipwd')->renderer()->behaviors(Behaviors::action(
				Generator::url('messages','mailbox','password',array('inlineid' => Generator::call('getInLineId'))),
				true
			)
	);
	$grid->initialize($user->personalMailers());
	$html .= $grid->display();
}
?>
<div>
	<div class="page-header clearfix"><?php echo $header->render();?></div>
	<div class="contentArea">
		<div class="mbs ">
			<?php echo $html;?>
		</div>
	</div>
</div>